package com.xiaobo.framework.service.order;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaobo.framework.api.bean.IboOrder;
import com.xiaobo.framework.api.response.OrderListResponse;
import com.xiaobo.framework.repository.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author: <a href="get_xiaobo@163.com">Josh_Xu</a>
 * @description:
 * @create: 2020-08-18 16:34
 **/
@Service
@Slf4j
public class OrderSerice extends ServiceImpl<OrderMapper, IboOrder> {

    private final OrderMapper orderMapper;

    @Autowired
    public OrderSerice(OrderMapper orderMapper) {
        this.orderMapper = orderMapper;
    }

    /**
     * @param var 订单类型
     * @return
     */
    public List<OrderListResponse> orderList(String var) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("order_type", var);
        List<IboOrder> list = this.orderMapper.selectList(queryWrapper);

        List<OrderListResponse> collect = list.stream().map(var1 -> {
            OrderListResponse orderListResponse = new OrderListResponse();
            BeanUtils.copyProperties(var1, orderListResponse);
            return orderListResponse;
        }).collect(Collectors.toList());
        return collect;
    }

}
